#ifndef __OgreURLSHA1_H__
#define __OgreURLSHA1_H__
#pragma once

// Include stuff
#include "OgreURLPrerequisites.h"

namespace Ogre
{
	/**
	 * @brief The implementation of secure hash algorithm 1 (SHA1),
	 * see RFC 3174
	 */
	class _OgreURLExport SHA1 : public GeneralAllocatedObject
	{
	public:
		/**
		 * @brief Default constructor
		 */
		SHA1();

		/**
		 * ~brief Default destructor
		 */
		~SHA1();

		/**
		 * @brief Updating SHA object
		 * @note Throw an exception if SHA object is finalized
		 */
		void update( const void* data, size_t size );

		/**
		 * @brief Updating SHA object
		 * @note Throw an exception if SHA object is finalized
		 */
		void update( const String& data );

		/**
		 * @brief Returns the digest of the strings passed to the update() method so far.
		 */
		const String& getHexDigest();

	protected:
		/**
		 * @brief Transform 32 bytes block
		 */
		void transform( unsigned long* block );

		/**
		 * @brief Finalize hash algorithm
		 */
		void finalize();

	protected:
		/// Digests container
		unsigned long mDigest[5];
		/// Container for 64 bytes data portion
		unsigned char mBlock64[64];
		/// Block used position
		int mBlockUsed;
		/// High length field 
		unsigned long mLenHi;
		// Lowlenght field
		unsigned long mLenLo;
		/// Result hash
		unsigned char mHash[20];
		/// Is algorithm finalized?
		bool mFinalized;
		/// Hex digest string;
		String mHexDigest;
	};

} // end of namespace Ogre

#endif // include guard, end of #ifndef __OgreURLSHA1_H__
